$(function(){
    $(".verfiy").click(function(){
        var timenow = new Date().getTime();
        $("#verfiy").attr("src","/user.php?m=Member&c=Login&a=verfiy&t="+timenow)
    });


});

var error = new Array();
//验证用户名是否已经被注册
function usernamefun(){ 
	var username=$('input[name="username"]').val();
	var userlength=username.length;
	if(userlength<3||userlength>15)
	{
        error['username'] = 0;
		 $("#userInfo").css('color','red');
		 $('#userInfo').text("用户名必须为3-15位");
		 $('#userImg').hide();	 
	}else
	{
		 $.post("/user.php?m=Member&c=Login&a=checkName",{'username':username},function(data){
			 $('#userInfo').text('');
			if(data.status==0){
                error['username'] = 0;
				$('#userImg').hide();
				$("#userInfo").css('color','red');
                $('#userInfo').text("用户名已经存在");
			}else{
                error['username'] = 1;
				$('#userInfo').text("");
				$('#userImg').show();
			}
		  });
	}
}

//验证密码长度
function passwordfun(){
		var password=$('input[name="password"]').val();
		var passlength=password.length;
		if(passlength<6||passlength>16)
		{
            error['password'] = 0;
			 $('#passImg').hide();
			 $("#passInfo").css('color','red');
			 $('#passInfo').text("密码为6-16位字符，尽量不要使用过于简单的密码");
		}else
		{
            error['password'] = 1;
			$('#passInfo').text("");
			$('#passImg').show();
		}	   
	}
//验证手机号码
	function phonefun(){						
		var mobile =$('input[name="mobile"]').val();
		var mobile_length=mobile.length;
		var reNum =/^0{0,1}(13[0-9]|15[5-9]|15[0-3]|177|18[5-9]|18[0-3])[0-9]{8}$/;
		if(!reNum.test(mobile))
		{
			$("#telImg").hide();
			$("#telInfo").css('color','red');
			$('#telInfo').text('请输入正确手机号手机号码');
			$('#denglu').text('');
		}else
		{
			$.post("/user.php?m=Member&c=Login&a=checkName",{'mobile':mobile},function(data){
				$('#telInfo').text(data.info);
				if(data.status==0){
                    error['mobile'] = 0;
					$("#telImg").hide();
					$("#telInfo").css('color','red');
					$('#telInfo').text('该手机号码已经注册过');
					$('#denglu').text(',请登录');
				}else{
                    error['mobile'] = 1;
					$("#telImg").show();
					$('#telInfo').text('');
					$('#denglu').text('');
				}
			  });
		}	   
	}
//验证邮箱号码
function emailfun(){
    var email =$('input[name="email"]').val();
    var email_length=email.length;
    var reNum = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if(!reNum.test(email))
    {
        $("#emailImg").hide();
        $("#emailInfo").css('color','red');
        $('#emailInfo').text('请输入正确邮箱号码');
        $('#denglu').text('');
    }else
    {
        $.post("/user.php?m=Member&c=Login&a=checkName",{'email':email},function(data){
            $('#emailInfo').text(data.info);
            if(data.status==0){
                error['email'] = 0;
                $("#emailImg").hide();
                $("#emailInfo").css('color','red');
                $('#emailInfo').text('该邮箱已经注册过');
                $('#denglu').text('');
            }else{
                error['email'] = 1;
                $("#emailImg").show();
                $('#emailInfo').text('');
                $('#denglu').text('');
            }
        });
    }
}


//验证两次密码是否输入一致
	function repasswordfun(){
		var repassword=$('input[name="repassword"]').val();
		var password=$('input[name="password"]').val();	
		if(repassword!=password){
            error['repassword'] = 0;
			$('#repassImg').hide();
			 $("#repassInfo").css('color','red');
			 $('#repassInfo').text("两次密码输入不一致");
		}else{
            error['repassword'] = 1;
			$('#repassInfo').text("");
			$('#repassImg').show();	
		}			   
	}

//注册页面提交表单
	function onregsubmit(){		
		if(error['username']!=1 || $("#username").val()=="")
		{
			alert('请填写正确的用户名');
			$("#username").focus();
			return false;
		}else if(error['password']!=1||$("#password").val()=="")
		{
			alert('请填写符合规格的密码');
			$("#password").focus();
			return false;
		}else if(error['mobile']!=1||$("#mobile").val()=="")
		{
			alert('请填写正确的手机号码');
			$("#tel").focus();
			return false;
		}else if(error['repassword']!=1||$("#repassword").val()=="")
		{
			alert('两次密码输入不一致');
			$("#repassword").focus();
			return false;
		}else if($("#captcha_code").val()=="")
		{
			alert('验证码输入错误');
			$("#captcha_code").focus();
			return false;
		}else if($("#captcha_code").val()){
            $("#myForm").submit();
        }

	}



